/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 29
 * Time: 9:17
 */
//牛客NC228 判断子序列
public class Solution1 {
    //法一（我的方法）
    public boolean isSubsequence1 (String S, String T) {
        char[] arr1 = S.toCharArray();
        char[] arr2 = T.toCharArray();
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                if(arr1[i] == arr2[j]) {
                    arr1[i] = 0;
                    arr2[i] = 0;
                    break;
                }
            }
        }
        for (int i = 0; i < arr1.length; i++) {
            if(arr1[i] != 0) {
                return false;
            }
        }
        return true;
    }

    //法二
    public boolean isSubsequence2 (String S, String T) {
        int lenS = S.length();
        int lenT = T.length();
        int i = 0;
        int j = 0;
        while (i < lenS && j < lenT) {
            if (S.charAt(i) == T.charAt(j)) {
                i++;
                j++;
            } else {
                j++;
            }
        }
        return i == lenS;
    }
}
